<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>附近管理</title>
<jsp:include page="../inc.jsp"></jsp:include>

	<script type="text/javascript"
	src="${pageContext.request.contextPath}/plug-in/custom/form.js"
	charset="utf-8"></script>
<script type="text/javascript">
	Ext.onReady(function(){
		Ext.QuickTips.init();
		createGrid();
		createLayout();

	});
	
	var gridEl = 'repTime-grid';
	var grid, form, selModel, toolbar, searchFlds;
	var win;
	
	function createGrid(){
		var queryFlds = new Array();
		searchFlds = new Ext.util.MixedCollection();
		var fldTimeName = new Ext.form.TextField({
			name : 'attachmenttitle',
			id : gridEl + '-name',
			fieldLabel : '名称',
			allowBlank : true,
			width : 200
		});
        searchFlds.add('attachmenttitle', fldTimeName);
        searchFlds.add('businessKey', new Ext.form.Hidden({
            name: 'businessKey',
            value: '<%=request.getParameter("businessKey")%>'
        }));
		grid =	Ext.create('gridView',{
			remoteSort : true,
			gridId : gridEl,
			checkboxSelectionModel:true,
			queryFlds : queryFlds,
			searchFlds : searchFlds,
			entityClassName : 'com.rover.system.entity.Attachment',
			queryUrl : 'attachmentController/query.action',
			deleteUrl : 'attachmentController/delete.action',
			recordPk : [ "id" ],
			expander:{text:'配置',  
				   menuDisabled: true,  
				   sortable: false,
				   align:'center',  
				   xtype: 'actioncolumn',  
				   width: 60,  
				   items: [{ icon   :'../images/smallIcon/settings.png', id: 'upArraw',    tooltip: '配置该项',  
				       handler: function(grid, rowIndex, colIndex) {   //rowIndex，colIndex均从0开始  
				    	   var rec = grid.getStore().getAt(rowIndex);  
				           grid.currentRowIndex = rowIndex;
				           createValueWindows( rec.data.isTree,rec.data.id);
				       } }]}
		});
		
	}
	
	
	// 刷新列表
	function reloadRecords() {
		grid.getStore().reload();
	}
	 var winValue;
		function createValueWindows(isTree,codeId) {
			var url="codeValueList.jsp?codeId="+codeId;
		   if(isTree==1){
			   var url="codeValueTreeList.jsp?codeId="+codeId;
		   }

			winValue = new Ext.Window({
					title : '代码值',
					iconCls : 'icon-win',
					autoHeight : true,
					width : 600,
					height : 500,
					buttonAlign : 'center',
					buttons : [  {
						text : "关闭",
						id : "btnWinClose",
						handler : function() {
							winValue.close();
						}
					} ],
					layout : 'fit',
					plain : false,
					closable : false,
					modal : true,
					html: "<iframe width='100%' height='100%' frameborder='0' src='"+url+"'></iframe>"
				});
			winValue.show();
		}
		
	function createWindows() {
		if (win == null) {
			win = new Ext.Window({
				title : '新增',
				iconCls : 'icon-win',
				autoHeight : true,
                width : 600,
                height : 500,
				buttonAlign : 'center',
				buttons : [  {
					text : "关闭",
					id : "btnClose",
					handler : function() {
						win.hide();
					}
				} ],
				layout : 'fit',
				plain : false,
				closable : false,
				modal : true,
                html: "<iframe width='100%' height='100%' frameborder='0' src='uploadFile.jsp?businessKey=<%=request.getParameter("businessKey")%>'></iframe>"
			});
		}
		win.show();
	}
	

	// 新建或修改表单成功提交后,重新加载其父节点
	function afterCommitFormSuccess(operation, recordData) {
		onWinHide();
		grid.getStore().reload();
	}


	// 创建layout
	function createLayout() {
		toolbar = new Ext.Toolbar({
            enableOverflow : true,
			items : [ {
				text : "新增附件",
				iconCls : 'addIcon',
				id : "tlb_NEW",
				handler : function() {
					createWindows();
				}
			}, '-', {
				text : "删除",
				iconCls : 'deleteIcon',
				id : "tlb_DELETE",
				handler : function() {
					grid.deleteRecord();
				}
			}, "->",  searchFlds.get("name"), {
		        text: "搜索",
		        iconCls : 'searchIcon',
		        handler: function () {
		        	grid.load();
		        }
		    } ]
		});

		var viewport = new Ext.Viewport({
			layout : 'border',
			items : [ {
				layout : 'fit',
				region : 'north',
				border : false,
				items : [ toolbar ]
			}, {
				layout : 'border',
				region : 'center',
				border : false,
				items : [ grid ]
			} ]
		});

		viewport.doLayout();
	}

</script>
</head>
<body>
</body>
</html>